<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="盖子名称" prop="bottleCapName">
      <el-input v-model="dataForm.bottleCapName" placeholder="盖子名称"></el-input>
    </el-form-item>
    <el-form-item label="盖子型号" prop="bottleCapNo">
      <el-input v-model="dataForm.bottleCapNo" placeholder="盖子型号"></el-input>
    </el-form-item>
    <el-form-item label="盖子克重" prop="capWeight">
      <el-input v-model="dataForm.capWeight" placeholder="盖子克重"></el-input>
    </el-form-item>
    <el-form-item label="规格描述" prop="capDesc">
      <el-input v-model="dataForm.capDesc" placeholder="规格描述"></el-input>
    </el-form-item>
    <el-form-item label="盖子类别" prop="capType">
      <el-input v-model="dataForm.capType" placeholder="盖子类别"></el-input>
    </el-form-item>
    <el-form-item label="盖子的口径" prop="bottleOutDiameter">
      <el-input v-model="dataForm.bottleOutDiameter" placeholder="盖子的口径"></el-input>
    </el-form-item>
    <el-form-item label="盖子颜色" prop="capColor">
      <el-input v-model="dataForm.capColor" placeholder="盖子颜色"></el-input>
    </el-form-item>
    <el-form-item label="盖子的材质" prop="capMaterial">
      <el-input v-model="dataForm.capMaterial" placeholder="盖子的材质"></el-input>
    </el-form-item>
    <el-form-item label="盖子形状" prop="capShape">
      <el-input v-model="dataForm.capShape" placeholder="盖子形状"></el-input>
    </el-form-item>
    <el-form-item label="盖子开启方式" prop="capOpenCloseWay">
      <el-input v-model="dataForm.capOpenCloseWay" placeholder="盖子开启方式"></el-input>
    </el-form-item>
    <el-form-item label="等级，A级。B级" prop="relateLevel">
      <el-input v-model="dataForm.relateLevel" placeholder="等级，A级。B级"></el-input>
    </el-form-item>
    <el-form-item label="图片信息" prop="relateImageInfo">
      <el-input v-model="dataForm.relateImageInfo" placeholder="图片信息"></el-input>
    </el-form-item>
    <el-form-item label="关联中套尺寸" prop="relateCenterCoverSize">
      <el-input v-model="dataForm.relateCenterCoverSize" placeholder="关联中套尺寸"></el-input>
    </el-form-item>
    <el-form-item label="喷头中套配合" prop="sprayHeadCenterCoverWay">
      <el-input v-model="dataForm.sprayHeadCenterCoverWay" placeholder="喷头中套配合方式"></el-input>
    </el-form-item>
    <el-form-item label="备注" prop="remark">
      <el-input v-model="dataForm.remark" placeholder="备注"></el-input>
    </el-form-item>

    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          bottleCapName: '',
          bottleCapNo: '',
          capWeight: '',
          capDesc: '',
          capType: '',
          bottleOutDiameter: '',
          capColor: '',
          capMaterial: '',
          capShape: '',
          capOpenCloseWay: '',
          relateLevel: '',
          relateImageInfo: '',
          relateCenterCoverSize: '',
          sprayHeadCenterCoverWay: '',
          remark: '',
          createUser: '',
          createTime: '',
          updateUser: '',
          updateTime: '',
          parentId: ''
        },
        // dataRule: {
        //   bottleCapName: [
        //     { required: true, message: '盖子名称不能为空', trigger: 'blur' }
        //   ],
        //   bottleCapNo: [
        //     { required: true, message: '盖子型号不能为空', trigger: 'blur' }
        //   ],
        //   capWeight: [
        //     { required: true, message: '盖子克重不能为空', trigger: 'blur' }
        //   ],
        //   capDesc: [
        //     { required: true, message: '规格描述不能为空', trigger: 'blur' }
        //   ],
        //   capType: [
        //     { required: true, message: '盖子类别不能为空', trigger: 'blur' }
        //   ],
        //   bottleOutDiameter: [
        //     { required: true, message: '盖子的口径不能为空', trigger: 'blur' }
        //   ],
        //   capColor: [
        //     { required: true, message: '盖子颜色不能为空', trigger: 'blur' }
        //   ],
        //   capMaterial: [
        //     { required: true, message: '盖子的材质不能为空', trigger: 'blur' }
        //   ],
        //   capShape: [
        //     { required: true, message: '盖子形状不能为空', trigger: 'blur' }
        //   ],
        //   capOpenCloseWay: [
        //     { required: true, message: '盖子开启方式不能为空', trigger: 'blur' }
        //   ],
        //   relateLevel: [
        //     { required: true, message: '等级，A级。B级不能为空', trigger: 'blur' }
        //   ],
        //   relateImageInfo: [
        //     { required: true, message: '图片信息不能为空', trigger: 'blur' }
        //   ],
        //   relateCenterCoverSize: [
        //     { required: true, message: '关联中套尺寸不能为空', trigger: 'blur' }
        //   ],
        //   sprayHeadCenterCoverWay: [
        //     { required: true, message: '喷头中套配合方式不能为空', trigger: 'blur' }
        //   ],
        //   remark: [
        //     { required: true, message: '备注不能为空', trigger: 'blur' }
        //   ],
        //   createUser: [
        //     { required: true, message: '创建者不能为空', trigger: 'blur' }
        //   ],
        //   createTime: [
        //     { required: true, message: '创建时间不能为空', trigger: 'blur' }
        //   ],
        //   updateUser: [
        //     { required: true, message: '更新者不能为空', trigger: 'blur' }
        //   ],
        //   updateTime: [
        //     { required: true, message: '更新时间不能为空', trigger: 'blur' }
        //   ],
        //   parentId: [
        //     { required: true, message: '父级不能为空', trigger: 'blur' }
        //   ]
        // }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/relate/relatebottlecapinfo/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.bottleCapName = data.relateBottleCapInfo.bottleCapName
                this.dataForm.bottleCapNo = data.relateBottleCapInfo.bottleCapNo
                this.dataForm.capWeight = data.relateBottleCapInfo.capWeight
                this.dataForm.capDesc = data.relateBottleCapInfo.capDesc
                this.dataForm.capType = data.relateBottleCapInfo.capType
                this.dataForm.bottleOutDiameter = data.relateBottleCapInfo.bottleOutDiameter
                this.dataForm.capColor = data.relateBottleCapInfo.capColor
                this.dataForm.capMaterial = data.relateBottleCapInfo.capMaterial
                this.dataForm.capShape = data.relateBottleCapInfo.capShape
                this.dataForm.capOpenCloseWay = data.relateBottleCapInfo.capOpenCloseWay
                this.dataForm.relateLevel = data.relateBottleCapInfo.relateLevel
                this.dataForm.relateImageInfo = data.relateBottleCapInfo.relateImageInfo
                this.dataForm.relateCenterCoverSize = data.relateBottleCapInfo.relateCenterCoverSize
                this.dataForm.sprayHeadCenterCoverWay = data.relateBottleCapInfo.sprayHeadCenterCoverWay
                this.dataForm.remark = data.relateBottleCapInfo.remark
                this.dataForm.createUser = data.relateBottleCapInfo.createUser
                this.dataForm.createTime = data.relateBottleCapInfo.createTime
                this.dataForm.updateUser = data.relateBottleCapInfo.updateUser
                this.dataForm.updateTime = data.relateBottleCapInfo.updateTime
                this.dataForm.parentId = data.relateBottleCapInfo.parentId
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/relate/relatebottlecapinfo/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'bottleCapName': this.dataForm.bottleCapName,
                'bottleCapNo': this.dataForm.bottleCapNo,
                'capWeight': this.dataForm.capWeight,
                'capDesc': this.dataForm.capDesc,
                'capType': this.dataForm.capType,
                'bottleOutDiameter': this.dataForm.bottleOutDiameter,
                'capColor': this.dataForm.capColor,
                'capMaterial': this.dataForm.capMaterial,
                'capShape': this.dataForm.capShape,
                'capOpenCloseWay': this.dataForm.capOpenCloseWay,
                'relateLevel': this.dataForm.relateLevel,
                'relateImageInfo': this.dataForm.relateImageInfo,
                'relateCenterCoverSize': this.dataForm.relateCenterCoverSize,
                'sprayHeadCenterCoverWay': this.dataForm.sprayHeadCenterCoverWay,
                'remark': this.dataForm.remark,
                'createUser': this.dataForm.createUser,
                'createTime': this.dataForm.createTime,
                'updateUser': this.dataForm.updateUser,
                'updateTime': this.dataForm.updateTime,
                'parentId': this.dataForm.parentId
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
